/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2021并保留所有权利。
 * Copyright 2021, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.singleton.exaple.隆来创建一个新对象单例模式也相应的失效;

public class Singleton implements Cloneable{
        private static Singleton instance = new Singleton();
        private Singleton(){}
        public static Singleton getInstance(){
            return instance;
        }
    
        public static void main(String[] args) {
            Singleton getInstance1 = Singleton.getInstance();
            Singleton getInstance2 = Singleton.getInstance();
            System.out.println("Is singleton pattern normally valid: " + (getInstance1 == getInstance2));
            try {
                Singleton cloneInstance3 = (Singleton) getInstance1.clone();
                System.out.println("Is singleton pattern valid for clone: " + (getInstance1 == cloneInstance3));
            } catch (CloneNotSupportedException e) {
                e.printStackTrace();
            }
        }
    }